<?php
namespace Tools;
use Think\Controller;

class AdminController extends Controller {
    
    function __construct() {
        parent::__construct();
        
        //获得当前的‘控制器-操作方法’
        $nowac = CONTROLLER_NAME."-".ACTION_NAME;
        
        //获取登陆者信息
        $admin_id = session('admin_id');
        $admin_name = session('admin_name');
        
        //公共权限
        $public_ac = "Login-login,Login-verifyImg,Index-find";
        
        //判断是否登陆了
        if(empty($admin_id) && strpos($public_ac, $nowac)===false) {
            $this ->redirect('Login/login');   
        }
        
        //用户信息，角色id
        $user = D('User') -> find($admin_id);
        $role_id = $user['user_role_id'];
        
        //角色信息,权限auth_ac
        $role = D('Role') -> find($role_id);
        $auth_acs = $role['role_auth_ac'];
        
        //判断访问的‘控制器-操作方法’是否拥有
        //或者在公共权限里边
        if(strpos($auth_acs,$nowac)===false  && strpos($public_ac,$nowac)===false ){
            exit("无权限");
        }              
    }

    
    function alert($message){
        echo "<script>alert('{$message}');</script>";
    }
    
}